#include <stdio.h>
typedef struct {
int numarator;
int numitor;
} Rational;
int cmmdc(Rational x);
Rational adunare (Rational, Rational);
Rational simplificare(Rational);
Rational opus (Rational);
Rational diferenta (Rational, Rational);
Rational imultire(Rational, Rational);
Rational invers(Rational);
Rational impartire(Rational, Rational);
int main ()
{
Rational x,y;
printf("Introduceti numaratorul pt x:"); scanf("%d",&x.numarator);
printf("Introduceti numitorul pt x:"); scanf("%d",&x.numitor);
printf("Introduceti numaratorul pt y:"); scanf("%d",&y.numarator);
printf("Introduceti numitorul pt y:"); scanf("%d",&y.numitor);
printf("Cmmdc pt x este: %d \n",cmmdc(x));
printf("x+y=%d/%d \n",adunare(x,y).numarator,adunare(x,y).numitor);
printf("Opusul lui y este:%d/%d\n",opus(y).numarator,opus(y).numitor);
printf("x-y=%d/%d\n",diferenta(x,y).numarator,diferenta(x,y).numitor);
printf("x*y=%d/%d \n",imultire(x,y).numarator,imultire(x,y).numitor);
printf("Inversul lui y este:%d/%d\n",invers(y).numarator,invers(y).numitor);
printf("x/y:%d/%d\n",impartire(x,y).numarator,impartire(x,y).numitor);
return 0;
}

int cmmdc(Rational x)
{
if (x.numarator==0) return x.numitor;
while (x.numitor!=0)
if (x.numarator>x.numitor) x.numarator=x.numarator-x.numitor;
else x.numitor=x.numitor-x.numarator;
return x.numarator;
}

Rational adunare (Rational x, Rational y)
{
Rational a;
a.numarator=x.numarator*y.numitor+y.numarator*x.numitor;
a.numitor=x.numitor*y.numitor;
return simplificare(a);
}
Rational simplificare (Rational x)
{
Rational s;
int c;
c=cmmdc(x);
s.numarator=x.numarator/c;
s.numitor=x.numitor/c;
return s;
}
Rational opus(Rational x)
{
Rational o;
o.numarator=-x.numarator;
o.numitor=x.numitor;
return o;
}
Rational diferenta (Rational x, Rational y)
{
Rational d;
d=adunare(x,opus(y));
return simplificare(d);
}
Rational imultire (Rational x, Rational y)
{
Rational p;
p.numarator=x.numarator*y.numarator;
p.numitor=x.numitor*y.numitor;
return simplificare(p);
}
Rational invers(Rational x)
{
Rational inv;
inv.numarator=x.numitor;
inv.numitor=x.numarator;
return inv;
}
Rational impartire (Rational x, Rational y)
{
Rational i;
i=imultire(x,invers(y));
return simplificare(i);
}

